﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using CE.User;

public partial class travel_insurance_UserMessage : System.Web.UI.Page
{
    protected string _header;
    protected string _body;
    protected string _headerMsg;
    protected string _bodyMsg;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string ProviderId, referencenum, emailadd;
            ProviderId = "0"; referencenum = ""; emailadd = "";
            if (Request.QueryString["pcid"] != null)
            {
                ProviderId = Decode(Request.QueryString["pcid"]).ToString();
                if (ProviderId == "23")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCTI_UserMessageEmail");

                    GetMessage(400, "TI", 23200);
                    _headerMsg = string.Format(_header);
                    _bodyMsg = string.Format(_body, referencenum, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                    //lblMessageHeader.Text = "Thank you for submitting the application for TravelSurance Quotation";
                    //lblMessageBody.Text = "HSBC Insurance officer will contact you shortly to finalise the transaction. The quotation reference number is " + referencenum + ". For urgent submission or further assistance, you may contact HSBC Insurance at (65)6225 6111 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";

                }
                else if (ProviderId == "29")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyTI_UserMessageEmail");

                    GetMessage(400, "TI", 29200);
                    _headerMsg = string.Format(_header, referencenum);
                    _bodyMsg = string.Format(_body, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                    //lblMessageHeader.Text = "Proposal reference: " + referencenum + "<br/><br/>"
                    //    + "Thank you. Your completed proposal form is submitted to Liberty Insurance.";

                    //lblMessageBody.Text = "Liberty will email you the confirmation within 1 working day. <br/><br/>"
                    //    + "If you have queries, you may contact 6221 8611 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";


                }
                else if (ProviderId == "24")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("RSATI_UserMessageEmail");

                    GetMessage(400, "TI", 24200);
                    _headerMsg = string.Format(_header, referencenum);
                    _bodyMsg = string.Format(_body, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                    //lblMessageHeader.Text = "Proposal reference: " + referencenum + "<br/><br/>"
                    //    + "Thank you. Your completed proposal form is submitted to RSA Insurance Group.";

                    //lblMessageBody.Text = "RSA will email you the confirmation within 1 working day. <br/><br/>"
                    //    + "If you have queries, you may contact 6423 0888 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";
                }

                else if (ProviderId == "34")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ChinaTI_UserMessageEmail");

                    GetMessage(400, "TI", 34200);
                    _headerMsg = string.Format(_header, referencenum);
                    _bodyMsg = string.Format(_body, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;

                }
                else if (ProviderId == "35")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EQTI_UserMessageEmail");

                    GetMessage(400, "TI", 35200);
                    _headerMsg = string.Format(_header, referencenum);
                    _bodyMsg = string.Format(_body, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;
                }
                else if (ProviderId == "36")
                {
                    referencenum = Request.QueryString["ref"].ToString();
                    emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ACETI_UserMessageEmail");

                    GetMessage(400, "TI", 36200);
                    _headerMsg = string.Format(_header, referencenum);
                    _bodyMsg = string.Format(_body, emailadd, emailadd);
                    lblMessageHeader.Text = _headerMsg;
                    lblMessageBody.Text = _bodyMsg;
                }
               
            }
            else
            {
                Response.Redirect("~/");
                //Response.Redirect("~/Home.aspx");
            }
            CE.Global.General.ClearAllSession(this.Page, "ALL");
        }
    }

    private void GetMessage(Int32 UserTypeId, string MessageType, Int32 ErrorCode)
    {
        MessageDB _messagedb = new MessageDB();
        DataTable _Message = new DataTable();
        _Message = _messagedb.GetMessage(UserTypeId, MessageType, ErrorCode);
        if (_Message != null && _Message.Rows.Count > 0)
        {
            _header = _Message.Rows[0]["Header"].ToString();
            _body = _Message.Rows[0]["Body"].ToString();
        }
        else
        {
            _header = "CompareXpress";
            _body = "No message found!";
        }
    }

    public string Decode(string sData)
    {
        try
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char);
            return result;
        }
        catch (Exception ex)
        {
            Response.Redirect("~/");
            //Response.Redirect("~/Home.aspx");
            string result = "";
            return result;
        }
    }
}
